package org.liuhy.line
{
	import flash.geom.Point;
	
	import mx.core.UIComponent;
	
	public class Arrow extends UIComponent
	{
		public function Arrow()
		{
			super();
		}
		//箭头的大小
        public var radius:int=4;
        public var fromPoint:Point;
        public var toPoint:Point;
        //线性的颜色
        public var lineColor:uint=0x000000;
        //是否需要画箭头
        public var needArrow:Boolean=true;
        
        private function getAngle():int
        {
            var  tmpx:int=toPoint.x-fromPoint.x ;
            var tmpy:int=fromPoint.y -toPoint.y ;
            var angle:int= Math.atan2(tmpy,tmpx)*(180/Math.PI);
            return angle;
        }
        
        //绘制线
        public function draw():void
        {
            this.graphics.clear();
//            this.graphics.lineStyle(1,lineColor,1);
//            this.graphics.moveTo(fromPoint.x,fromPoint.y);
//            this.graphics.lineTo(toPoint.x,toPoint.y);
//            
//            if(needArrow)
//            {
                var angle:int =getAngle();
                var centerX:int=toPoint.x-radius * Math.cos(angle *(Math.PI/180)) ;
                var centerY:int=toPoint.y+radius * Math.sin(angle *(Math.PI/180)) ;
                var topX:int=toPoint.x ;
                var topY:int=toPoint.y  ;
                
                var leftX:int=centerX + radius * Math.cos((angle +120) *(Math.PI/180))  ;
                var leftY:int=centerY - radius * Math.sin((angle +120) *(Math.PI/180))  ;
                
                var rightX:int=centerX + radius * Math.cos((angle +240) *(Math.PI/180))  ;
                var rightY:int=centerY - radius * Math.sin((angle +240) *(Math.PI/180))  ;
                
                this.graphics.beginFill(lineColor,1);
                
                this.graphics.lineStyle(1,lineColor,1);
                
//                this.graphics.moveTo(topX,topY);
//                this.graphics.lineTo(leftX,leftY);
//                
//                this.graphics.lineTo(centerX,centerY);
//                
//                this.graphics.lineTo(rightX,rightY);
//                this.graphics.lineTo(topX,topY);
                
                
                this.graphics.moveTo(topX,topY);
                this.graphics.lineTo(leftX,leftY);
                
//                this.graphics.lineTo(centerX,centerY);
                
                this.graphics.lineTo(rightX,rightY);
                this.graphics.lineTo(topX,topY);
                
                this.graphics.endFill();
//            }
        }
        


	}
}